package jdbc;

import java.sql.Connection;
import java.sql.Driver;
import java.sql.DriverManager;
import java.sql.Statement;

/**
 * JDBC java数据库链接
 */
public class demo1 {
    public static void main(String[] args) throws Exception {
        //1加载驱动
        Class.forName("com.mysql.cj.jdbc.Driver");
        //2
        Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/tedu?characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai&rewriteBatchedStatements=true",
                "root","byb141700");
        System.out.println("与数据库正常链接！");
        //3
        Statement statement = connection.createStatement();

        String sql = "CREATE TABLE user5(\n"+
                "id INT PRIMARY KEY AUTO_INCREMENT,\n"+
                "name VARCHAR(20) NOT NULL,\n"+
                "password VARCHAR(20) NOT NULL,\n"+
                "nickname VARCHAR(50) NOT NULL,\n"+
                "age INT(3)\n"+
                ")";
        System.out.println(sql);
        statement.execute(sql);
        System.out.println("创建表成功！");
        statement.close();
    }
}
